import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

class TextInputMultipleAdd extends StatelessWidget {
  /// controller 用户获取或者赋值输入内容
  final TextEditingController? controller;

  /// 输入框背景
  final Color? backgroundColor;

  /// 提示文案
  final String? hintText;

  /// 输入框左侧文案
  final String leftLabel;

  /// 第一个时customParam 的内容
  final String? Function(dynamic)? editCallBack;

  /// 是否必填标志（红色*）
  final bool required;

  /// 带图标的输入框
  final Widget? leftIcon;

  /// leftLabel右侧组件，支持自定义
  final Widget? labelWidget;

  /// 字体大小
  final double labelSize;

  /// 提示文本颜色，默认为文本颜色
  final TextStyle? hintTextStyle;

  /// 是否只读
  final bool readOnly;

  /// 键盘类型，数字、字母
  final TextInputType? inputType;

  /// 是否展示底部分割线
  final bool showBottomDivider;
  final  int minLines;

  /// 内容对齐方向
  final TextAlign contentAlignment;

  //  构造函数

  const TextInputMultipleAdd({
    Key? key,
    this.backgroundColor,
    this.controller,
    this.hintText,
    required this.leftLabel,
    this.required = false,
    this.readOnly = false,
    this.leftIcon,
    this.labelWidget,
    this.labelSize = 16,
    this.minLines = 2,
    this.inputType,
    this.hintTextStyle,
    this.contentAlignment = TextAlign.start,
    this.showBottomDivider = true,
    this.editCallBack,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(alignment: Alignment.bottomCenter, children: [
      Container(
          color: Colors.white,
          padding: EdgeInsets.symmetric(horizontal: 10),
          child: Column(
            children: [
              _buildLeft(),
              _buildRight(),
            ],
          )),
      const TDDivider(
        margin: EdgeInsets.only(
          left: 16,
        ),
      )
    ]);
  }

  Widget _buildLeft() {
    String mustBeEnter = required ? "*" : " ";
    return Row(children: [
      Container(
          margin: EdgeInsets.only(top: 14),
          child: Text(
            mustBeEnter,
            style: TextStyle(color: Colors.red, fontSize: labelSize - 2),
          )),
      Text(
        leftLabel,
        style: TextStyle(fontSize: labelSize, color: Colors.black),
      ),
    ]);
  }

  Widget _buildRight() {
    return TextField(
      controller: controller,
      minLines: minLines,
      maxLines: minLines+4,
      textAlign: contentAlignment,
      decoration: InputDecoration(
        hintText: hintText,
        hintStyle: hintTextStyle ??
            TextStyle(color: TDTheme.of(Get.context!).fontGyColor3),
        enabledBorder: const UnderlineInputBorder(
          borderSide: BorderSide(color: Colors.transparent),
        ),
        focusedBorder: const UnderlineInputBorder(
          borderSide: BorderSide(color: Colors.transparent),
        ),
      ),
    );
  }
}
